package cn.tansanqinger.controller.topic;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.hymenu.IHyMenuServer;
import cn.tansanqinger.service.topic.ITopicService;
import cn.tansanqinger.util.PageData;

@RequestMapping("/topic/user")
@Controller
public class TopicUpdataController {
	
	@Autowired
	private ITopicService service;
	@Autowired
	private IHyMenuServer hyMenuServer;

	@RequestMapping("/list")
	public ModelAndView list(HttpServletRequest request, ModelAndView mv) {
		mv.setViewName("topic/list");
		return mv;
	}
	
	@RequestMapping("/list2")
	public ModelAndView list2(HttpServletRequest request, ModelAndView mv) {
		mv = hyMenuServer.selectHyMenuAll(mv);
		mv.addObject("topicCountAll", service.topicCountAll(request));
		mv.addObject("user", request.getSession().getAttribute("user"));
		mv.addObject("topicList", service.selectTeacherUpdata(request));
		mv.setViewName("topic/list2");
		return mv;
	}
	
	@RequestMapping("/addTopic")
	@ResponseBody
	public PageData addTopic(HttpServletRequest request) {
		return service.addUpdata(request);
	}
	
	/**
	 * 编辑信息
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/edit")
	public ModelAndView edit(HttpServletRequest request, ModelAndView mv) {
		System.err.println(service.selectTeacherUpdataOne(request));
		mv.addObject("topic", service.selectTeacherUpdataOne(request));
		mv.setViewName("topic/edit");
		return mv;
	}
	
	/**
	 * 修改信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/modification")
	@ResponseBody
	public PageData modification(HttpServletRequest request){
		return service.modificationTeacherUpdata(request);
	}
	
	/**
	 * 删除数据
	 * @param request
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public PageData delete(HttpServletRequest request) {
		return service.deleteTeacherUpdata(request);
	}
}